<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import { initRequestParams } from '@/request'

export default {
  name: 'app',
  
  async mounted() {
    // 保存用户信息
    if(localStorage.getItem('userinfo')) {
      const user = JSON.parse(localStorage.getItem('userinfo'))
      this.$store.commit('user/setUser', user)
      initRequestParams(this.$store.getters['user/token'])
    } else {
      this.$router.push('/')
    }

    if(localStorage.getItem('navInfo')) {
      const {navName, role , menuActive ,gotoMenuLayOut} = JSON.parse(localStorage.getItem('navInfo'))
      if(navName && role) {
        this.$store.commit('nav/setOperate', navName)
        this.$store.commit('nav/initNav', {
            role
        })
        this.$store.commit('nav/setMenuActive', menuActive)
        const path = location.hash.substring(1)

        if(path.search('/admin') === 0) return;

        if(gotoMenuLayOut.includes(navName)) {
          if(path === `/main/${navName}`) return;
          this.$router.push(`/main/${navName}`)
        }else {
          if(path.search('/office') === 0) return;
          this.$router.push(`/office`)
        }
      }
    } 

  },
  methods: {
    async cli() {
      const data = await this.$post('first', {
        data: {
          test: 123,
          b: 5
        }
      })
      console.log(data)
    }
  }
}
</script>

<style scoped lang="scss">

</style>
